<template>
  <div class="headNav">
    <div class="left">
      <img src="../assets/images/logo.png" />
      <h2>资金管理系统</h2>
    </div>
    <div class="right">
      <div class="userInfo">
        <img src="../assets/images/logo.png" class="avator"/>
        <div class="welcome">
          <p class="name comename">欢迎</p>
          <p class="name avatorname">{{ user.name }} </p>
        </div>
        <span class="username" >
         <el-dropdown trigger="click" @command="setDialogInfo">
            <span class="el-dropdown-link">
              <!-- el-icon 是 Element Plus 的图标组件 -->
              <el-icon><ArrowDown /></el-icon>
            </span>
            <template #dropdown>
              <!-- el-dropdown-menu 是下拉菜单项容器 -->
              <el-dropdown-menu>
                <!-- el-dropdown-item 表示下拉菜单项 -->
                <!-- command 属性指定点击项的命令 -->
                <el-dropdown-item command="info">个人中心</el-dropdown-item>
                <el-dropdown-item command="logout">退出</el-dropdown-item>
              </el-dropdown-menu>
            </template>
          </el-dropdown>
        </span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ArrowDown } from "@element-plus/icons"; // 引入 Element Plus 的箭头图标
import { computed } from "vue"; // 引入 Vue 3 的 computed 函数
import { useStore } from "vuex"; // 引入 Vuex 的 useStore 函数
import { useRouter } from "vue-router"; // 引入 Vue Router 的 useRouter 函数
const router = useRouter(); // 创建 Vue Router 实例
const store = useStore(); // 获取 Vuex store 实例

const user = computed(() => {
  return store.getters.user; // 从 Vuex store 中获取用户信息
});

const setDialogInfo = (cmdItem) => {
  switch (cmdItem) {
    case "info":
      showInfoList(); // 显示信息列表页面
      break;
    case "logout":
      logout(); // 执行退出操作
      break;
  }
};
const showInfoList = () =>{
  router.push('/infoshow');
};

const logout = () =>{
  localStorage.removeItem('mytoken');
  store.dispatch("clearCurrentStatus");
  router.push('/login');
}

</script>

<style lang="less" scoped>
.headNav {
  width: 100%;
  height: 50px;
  background-color: rgb(53, 25, 29);
  .left {
    display: flex;
    float: left;
    align-items: center;
    img {
      width: 50px;
      height: 50px;
    }
    h2 {
      color: white;
      padding: 10px;
      font-size: 19px;
      font-weight: bold;
      
    }
  }
  .right {
    float: right;
    margin-right: 50px;
    .userInfo {
      display: flex;
      align-items: center;
      height: 50px;
      .avator {
        width: 50px;
        height: 50px;
        border-radius: 50%;
      }
      .welcome {
        display: flex;
        flex-direction: column;
        align-items: center;
        margin-left: 10px;
        .name {
          color: #eeeff1;
          font-size: 14px;
          font-weight: 500;
          margin-right: 10px;
        }
        .avatorname{
          color: skyblue;
          padding-top: 5px;


        }
      }
      .username {
        .el-dropdown-link {
              cursor: pointer;
              color: #409EFF;
            }
            .el-icon-arrow-down {
              font-size: 12px;
            }
    }
  }
}}
</style>
